import java.awt.Graphics;
import java.awt.Point;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;

public class PLRect extends PLShape {	
	private static final long serialVersionUID = 1L;

	public PLRect() {		
		super(ShapeIdT.kRect);
	}
	public PLRect(Point start, Point end){		
		super(ShapeIdT.kRect);
		Parse(start, end);
	}
		
	// Attributes 
	public float GetWidth() { 
		return Math.abs((mStart.x - mEnd.x));
	}
	public float GetHeight() { 		
		return Math.abs((mStart.y - mEnd.y));
	}

	public float GetArea() { return GetHeight() * GetWidth(); }	
	public int GetStartingQuadrant() { // TODO 
		return 1;
	}
	
	public int GetEndingQuadrant() { // TODO 
		return 2;
	}	
	
	public Shape GetJavaShape(){
		return new Rectangle2D.Float(mStart.x, mStart.y, GetWidth(), GetHeight()); 
	}
	

	// Draw
	public void Draw(Graphics g){
		PLDebug.Info("Trying to draw rect"); 
		//reset mStart and mEnd to the upper left and bottom right, respectively
		Point start = new Point(Math.min(mEnd.x,mStart.x),Math.min(mEnd.y,mStart.y));
		try
		{
        		g.drawRect(start.x, start.y, (int)GetWidth(), (int)GetHeight() ); 
		}
		catch (NullPointerException e)
		{
			System.out.println("Null Pointer: Nothing to draw"); 
		}
	}


	// PROTECTED
	protected void SetupLines() {	
		mLines = new PLLine[4];	
		Point[] corners = GetCorners();

		mLines[0] = new PLLine(corners[0], corners[1]);
		mLines[1] = new PLLine(corners[1], corners[2]);
		mLines[2] = new PLLine(corners[2], corners[3]);
		mLines[3] = new PLLine(corners[3], corners[0]);		
	}
	
	protected void SetupCorners() {
		mCorners = new Point[4]; 
		
		Point start = new Point(Math.min(mEnd.x,mStart.x),Math.min(mEnd.y,mStart.y));
		
		mCorners[0] = new Point(start); 
		mCorners[1] = new Point((int)(start.x + GetWidth()), start.y);
		mCorners[2] = new Point((int)(start.x + GetWidth()), (int)(start.y + GetHeight()));
		mCorners[3] = new Point(start.x, (int)(start.y + GetHeight()));
	}	
}
